﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace YJKColumnModify.WallAlignToColumn
{
	public class ColumnFilter : ISelectionFilter
	{
		public ColumnFilter(Autodesk.Revit.DB.Document doc)
		{
			this.m_doc = doc;
		}

		public bool AllowElement(Element elem)
		{
			FamilyInstance familyInstance = elem as FamilyInstance;
			if (familyInstance == null)
			{
				return false;
			}
			Category category = familyInstance.Category;
			return -2001330 == category.Id.IntegerValue || -2000100 == category.Id.IntegerValue;
		}

		public bool AllowReference(Reference reference, XYZ position)
		{
			PlanarFace planarFace = this.m_doc.GetElement(reference).GetGeometryObjectFromReference(reference) as PlanarFace;
			return !planarFace.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ) && !planarFace.FaceNormal.IsAlmostEqualTo(-XYZ.BasisZ);
		}

		private Document m_doc;
	}
}
